package com.dobbinsoft.iotechn.device.mqtt.serializer;

import com.alibaba.fastjson.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * Description:
 * User: rize
 * Date: 2020/6/22
 * Time: 15:10
 */
public class IotMqttJsonDeserializer implements IotMqttDeserializer {

    @Override
    public <T> T parseObject(byte[] payload, Class<T> clazz) {
        try {
            return JSONObject.parseObject(new String(payload, "utf-8"), clazz);
        } catch (UnsupportedEncodingException e) {
            // 此处不可能
            throw new RuntimeException();
        }
    }

    @Override
    public <T> List<T> parseArray(byte[] payload, Class<T> clazz) {
        try {
            return JSONObject.parseArray(new String(payload, "utf-8"), clazz);
        } catch (UnsupportedEncodingException e) {
            // 此处不可能
            throw new RuntimeException();
        }
    }

}
